/*
 * JInternalFrameErrores.java
 *
 * Created on 15-ago-2011, 12:29:11
 */
package com.ufps.cuatro.vistas;

import java.util.ArrayList;

import javax.swing.JList;

import org.jdesktop.application.Action;

import com.ufps.cuatro.util.MsgInfo;
import com.ufps.cuatro.util.Utileria;
import com.ufps.cuatro.util.render.MyListRendererJLabel;
import com.ufps.cuatro.controlador.render.UtilRender;

/**
 *
 * @author Carlos A. Torres C. 
 */
public class JInternalFrameErrores extends javax.swing.JInternalFrame {
    private static final long serialVersionUID = 4305697632211667176L;

    /** Creates new form JInternalFrameErrores */
    public JInternalFrameErrores() {
        initComponents();
        this.jEditorPaneMSG.setEditable(false);
        if(Utileria.objMSG.isEmpty()){
            ArrayList<String> objMsg = new ArrayList<String>();
            objMsg.add("No hay Mensajes.");
            JList objLista = new JList(objMsg.toArray());
            this.jListMensajes.setModel(objLista.getModel());
        }
        else{
            JList objLista = new JList(Utileria.objMSG.toArray());
            this.jListMensajes.setModel(objLista.getModel());
            MyListRendererJLabel objRenderer = new MyListRendererJLabel(Utileria.ARBOL_COMPONENTES);
            this.jListMensajes.setCellRenderer(objRenderer);
        }        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListMensajes = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        jEditorPaneMSG = new javax.swing.JEditorPane();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(JInternalFrameErrores.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(JInternalFrameErrores.class, this);
        jButton1.setAction(actionMap.get("cerrarVentana")); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setName("jButton1"); // NOI18N
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton1);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jToolBar1.add(jSeparator1);

        jButton2.setAction(actionMap.get("help")); // NOI18N
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setName("jButton2"); // NOI18N
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton2);

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jSplitPane1.setDividerLocation(200);
        jSplitPane1.setName("jSplitPane1"); // NOI18N
        jSplitPane1.setOneTouchExpandable(true);

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jListMensajes.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jListMensajes.setName("jListMensajes"); // NOI18N
        jListMensajes.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListMensajesValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jListMensajes);

        jSplitPane1.setLeftComponent(jScrollPane1);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jEditorPaneMSG.setContentType(resourceMap.getString("jEditorPaneMSG.contentType")); // NOI18N
        jEditorPaneMSG.setName("jEditorPaneMSG"); // NOI18N
        jScrollPane2.setViewportView(jEditorPaneMSG);

        jSplitPane1.setRightComponent(jScrollPane2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 576, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(469, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jListMensajesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListMensajesValueChanged
        if(!this.jListMensajes.isSelectionEmpty()){
            this.jEditorPaneMSG.setContentType(java.util.ResourceBundle.getBundle("com/ufps/cuatro/vistas/util/resources/JInternalFramePopupHelpInfo").getString("TEXT/HTML"));
            MsgInfo objMSG = (MsgInfo) this.jListMensajes.getSelectedValue();
            String strMSG = "";
            strMSG += "<tr><td>Fecha:</td><td>" + objMSG.getFecha().toString() + "</td></tr>";
            strMSG += "<tr><td>Id de Mensaje:</td><td>" + objMSG.getIdMSG() + "</td></tr>";
            strMSG += "<tr><td>Titulo:</td><td>" + objMSG.getStrTitulo() + "</td></tr>";
            strMSG += "<tr><td>Descripción:</td><td>" + objMSG.getStrMSG() + "</td></tr>";
            strMSG += "<tr><td>Mensaje Java:</td><td>" + objMSG.getStrMSGJava() + "</td></tr>";            
            objMSG.setVisualizado(true);
            this.jEditorPaneMSG.setText(strMSG);            
        }
}//GEN-LAST:event_jListMensajesValueChanged

    @Action
    public void cerrarVentana() {
        if(Utileria.confirmarOrden(this, "¿Desea Cancelar el Proceso?", ""))
            dispose();
    }

    @Action
    public void help() {
        UtilRender.openDialogHelp(JInternalFrameErrores.class, getTitle());
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JEditorPane jEditorPaneMSG;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JList jListMensajes;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables
}
